<?php
require_once('../classes/Student.php');

session_start();

$student = new Student;
$username = mysql_real_escape_string($_POST['username']);
$userpass = mysql_real_escape_string($_POST['password']);
$studentAccount = $student->checkUserAccount($username,$userpass);

if(isset($_POST['log_in']))
{
    if($studentAccount==null){
        header('Location: ../index.php?action=loginerror=1');   
    }
    else{
        $_SESSION['login'] = 1;
        $find = mysql_query("SELECT stud_id FROM account WHERE username = '$username'");
        while($row = mysql_fetch_array($find, MYSQL_ASSOC)){
                $id = $row['stud_id'];
            }
        $find = mysql_query("SELECT stud_fname FROM account,student  WHERE account.stud_id = '$id'  AND student.stud_id = '$id'");
        while($row = mysql_fetch_array($find, MYSQL_ASSOC)){
                $_SESSION['fname'] = $row['stud_fname'];
            }
        $find = mysql_query("SELECT stud_lname FROM account,student  WHERE account.stud_id = '$id' AND student.stud_id = '$id'");
        while($row = mysql_fetch_array($find, MYSQL_ASSOC)){
                $_SESSION['lname'] = $row['stud_lname'];
            }
        echo $_SESSION['fname'].$_SESSION['lname'];
        header("Location: ../index.php");
    }
}
?>